<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 使用组合继承的方式，继承父构造函数的属性和方法

      function Father(uname, age, gender) {
        this.uname = uname

        this.age = age

        this.gender = gender
      }

      Father.prototype.money = function () {
        console.log('赚了一个小目标')
      }
      const father = new Father('董', 59, '男')
      console.log(father)
      father.money()
      function Son(uname, age, gender, face) {
        console.log(this) //Son {}
        Father.call(this, uname, age, gender)
        this.face = face
      }

      //原型链继承 继承父亲的方法可以继承父亲的实例化对象

      Son.prototype = new Father()
      console.log(Son.prototype) //Father {uname: undefined, age: undefined, gender: undefined}

      // 手动改变constructor的指向指回儿子的构造函数
      Son.prototype.constructor = Son

      Son.prototype.smoke = function () {
        console.log('我会抽烟')
      }

      const son = new Son('董', 18, '男', '帅')
      console.log(son)
      son.money() //赚了一个小目标
      son.smoke() //我会抽烟
      father.smoke()
    </script>
  </body>
</html>
